/**
 */
package mvc_generator.mVCGenerator.impl;

import java.util.Collection;

import mvc_generator.mVCGenerator.Config;
import mvc_generator.mVCGenerator.Controller;
import mvc_generator.mVCGenerator.MVCGeneratorPackage;
import mvc_generator.mVCGenerator.Model;
import mvc_generator.mVCGenerator.ModelMVC;
import mvc_generator.mVCGenerator.View;

import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.NotificationChain;

import org.eclipse.emf.common.util.EList;

import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.InternalEObject;

import org.eclipse.emf.ecore.impl.ENotificationImpl;
import org.eclipse.emf.ecore.impl.MinimalEObjectImpl;

import org.eclipse.emf.ecore.util.EObjectContainmentEList;
import org.eclipse.emf.ecore.util.InternalEList;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>Model MVC</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * <ul>
 *   <li>{@link mvc_generator.mVCGenerator.impl.ModelMVCImpl#getName <em>Name</em>}</li>
 *   <li>{@link mvc_generator.mVCGenerator.impl.ModelMVCImpl#getConfig <em>Config</em>}</li>
 *   <li>{@link mvc_generator.mVCGenerator.impl.ModelMVCImpl#getModel <em>Model</em>}</li>
 *   <li>{@link mvc_generator.mVCGenerator.impl.ModelMVCImpl#getViews <em>Views</em>}</li>
 *   <li>{@link mvc_generator.mVCGenerator.impl.ModelMVCImpl#getControllers <em>Controllers</em>}</li>
 * </ul>
 * </p>
 *
 * @generated
 */
public class ModelMVCImpl extends MinimalEObjectImpl.Container implements ModelMVC
{
  /**
   * The default value of the '{@link #getName() <em>Name</em>}' attribute.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #getName()
   * @generated
   * @ordered
   */
  protected static final String NAME_EDEFAULT = null;

  /**
   * The cached value of the '{@link #getName() <em>Name</em>}' attribute.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #getName()
   * @generated
   * @ordered
   */
  protected String name = NAME_EDEFAULT;

  /**
   * The cached value of the '{@link #getConfig() <em>Config</em>}' containment reference.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #getConfig()
   * @generated
   * @ordered
   */
  protected Config config;

  /**
   * The cached value of the '{@link #getModel() <em>Model</em>}' containment reference.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #getModel()
   * @generated
   * @ordered
   */
  protected Model model;

  /**
   * The cached value of the '{@link #getViews() <em>Views</em>}' containment reference list.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #getViews()
   * @generated
   * @ordered
   */
  protected EList<View> views;

  /**
   * The cached value of the '{@link #getControllers() <em>Controllers</em>}' containment reference list.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #getControllers()
   * @generated
   * @ordered
   */
  protected EList<Controller> controllers;

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  protected ModelMVCImpl()
  {
    super();
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  protected EClass eStaticClass()
  {
    return MVCGeneratorPackage.Literals.MODEL_MVC;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public String getName()
  {
    return name;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public void setName(String newName)
  {
    String oldName = name;
    name = newName;
    if (eNotificationRequired())
      eNotify(new ENotificationImpl(this, Notification.SET, MVCGeneratorPackage.MODEL_MVC__NAME, oldName, name));
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public Config getConfig()
  {
    return config;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public NotificationChain basicSetConfig(Config newConfig, NotificationChain msgs)
  {
    Config oldConfig = config;
    config = newConfig;
    if (eNotificationRequired())
    {
      ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, MVCGeneratorPackage.MODEL_MVC__CONFIG, oldConfig, newConfig);
      if (msgs == null) msgs = notification; else msgs.add(notification);
    }
    return msgs;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public void setConfig(Config newConfig)
  {
    if (newConfig != config)
    {
      NotificationChain msgs = null;
      if (config != null)
        msgs = ((InternalEObject)config).eInverseRemove(this, EOPPOSITE_FEATURE_BASE - MVCGeneratorPackage.MODEL_MVC__CONFIG, null, msgs);
      if (newConfig != null)
        msgs = ((InternalEObject)newConfig).eInverseAdd(this, EOPPOSITE_FEATURE_BASE - MVCGeneratorPackage.MODEL_MVC__CONFIG, null, msgs);
      msgs = basicSetConfig(newConfig, msgs);
      if (msgs != null) msgs.dispatch();
    }
    else if (eNotificationRequired())
      eNotify(new ENotificationImpl(this, Notification.SET, MVCGeneratorPackage.MODEL_MVC__CONFIG, newConfig, newConfig));
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public Model getModel()
  {
    return model;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public NotificationChain basicSetModel(Model newModel, NotificationChain msgs)
  {
    Model oldModel = model;
    model = newModel;
    if (eNotificationRequired())
    {
      ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, MVCGeneratorPackage.MODEL_MVC__MODEL, oldModel, newModel);
      if (msgs == null) msgs = notification; else msgs.add(notification);
    }
    return msgs;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public void setModel(Model newModel)
  {
    if (newModel != model)
    {
      NotificationChain msgs = null;
      if (model != null)
        msgs = ((InternalEObject)model).eInverseRemove(this, EOPPOSITE_FEATURE_BASE - MVCGeneratorPackage.MODEL_MVC__MODEL, null, msgs);
      if (newModel != null)
        msgs = ((InternalEObject)newModel).eInverseAdd(this, EOPPOSITE_FEATURE_BASE - MVCGeneratorPackage.MODEL_MVC__MODEL, null, msgs);
      msgs = basicSetModel(newModel, msgs);
      if (msgs != null) msgs.dispatch();
    }
    else if (eNotificationRequired())
      eNotify(new ENotificationImpl(this, Notification.SET, MVCGeneratorPackage.MODEL_MVC__MODEL, newModel, newModel));
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public EList<View> getViews()
  {
    if (views == null)
    {
      views = new EObjectContainmentEList<View>(View.class, this, MVCGeneratorPackage.MODEL_MVC__VIEWS);
    }
    return views;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public EList<Controller> getControllers()
  {
    if (controllers == null)
    {
      controllers = new EObjectContainmentEList<Controller>(Controller.class, this, MVCGeneratorPackage.MODEL_MVC__CONTROLLERS);
    }
    return controllers;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs)
  {
    switch (featureID)
    {
      case MVCGeneratorPackage.MODEL_MVC__CONFIG:
        return basicSetConfig(null, msgs);
      case MVCGeneratorPackage.MODEL_MVC__MODEL:
        return basicSetModel(null, msgs);
      case MVCGeneratorPackage.MODEL_MVC__VIEWS:
        return ((InternalEList<?>)getViews()).basicRemove(otherEnd, msgs);
      case MVCGeneratorPackage.MODEL_MVC__CONTROLLERS:
        return ((InternalEList<?>)getControllers()).basicRemove(otherEnd, msgs);
    }
    return super.eInverseRemove(otherEnd, featureID, msgs);
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public Object eGet(int featureID, boolean resolve, boolean coreType)
  {
    switch (featureID)
    {
      case MVCGeneratorPackage.MODEL_MVC__NAME:
        return getName();
      case MVCGeneratorPackage.MODEL_MVC__CONFIG:
        return getConfig();
      case MVCGeneratorPackage.MODEL_MVC__MODEL:
        return getModel();
      case MVCGeneratorPackage.MODEL_MVC__VIEWS:
        return getViews();
      case MVCGeneratorPackage.MODEL_MVC__CONTROLLERS:
        return getControllers();
    }
    return super.eGet(featureID, resolve, coreType);
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @SuppressWarnings("unchecked")
  @Override
  public void eSet(int featureID, Object newValue)
  {
    switch (featureID)
    {
      case MVCGeneratorPackage.MODEL_MVC__NAME:
        setName((String)newValue);
        return;
      case MVCGeneratorPackage.MODEL_MVC__CONFIG:
        setConfig((Config)newValue);
        return;
      case MVCGeneratorPackage.MODEL_MVC__MODEL:
        setModel((Model)newValue);
        return;
      case MVCGeneratorPackage.MODEL_MVC__VIEWS:
        getViews().clear();
        getViews().addAll((Collection<? extends View>)newValue);
        return;
      case MVCGeneratorPackage.MODEL_MVC__CONTROLLERS:
        getControllers().clear();
        getControllers().addAll((Collection<? extends Controller>)newValue);
        return;
    }
    super.eSet(featureID, newValue);
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public void eUnset(int featureID)
  {
    switch (featureID)
    {
      case MVCGeneratorPackage.MODEL_MVC__NAME:
        setName(NAME_EDEFAULT);
        return;
      case MVCGeneratorPackage.MODEL_MVC__CONFIG:
        setConfig((Config)null);
        return;
      case MVCGeneratorPackage.MODEL_MVC__MODEL:
        setModel((Model)null);
        return;
      case MVCGeneratorPackage.MODEL_MVC__VIEWS:
        getViews().clear();
        return;
      case MVCGeneratorPackage.MODEL_MVC__CONTROLLERS:
        getControllers().clear();
        return;
    }
    super.eUnset(featureID);
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public boolean eIsSet(int featureID)
  {
    switch (featureID)
    {
      case MVCGeneratorPackage.MODEL_MVC__NAME:
        return NAME_EDEFAULT == null ? name != null : !NAME_EDEFAULT.equals(name);
      case MVCGeneratorPackage.MODEL_MVC__CONFIG:
        return config != null;
      case MVCGeneratorPackage.MODEL_MVC__MODEL:
        return model != null;
      case MVCGeneratorPackage.MODEL_MVC__VIEWS:
        return views != null && !views.isEmpty();
      case MVCGeneratorPackage.MODEL_MVC__CONTROLLERS:
        return controllers != null && !controllers.isEmpty();
    }
    return super.eIsSet(featureID);
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public String toString()
  {
    if (eIsProxy()) return super.toString();

    StringBuffer result = new StringBuffer(super.toString());
    result.append(" (name: ");
    result.append(name);
    result.append(')');
    return result.toString();
  }

} //ModelMVCImpl
